package com.zcf.controller;


import com.qiniu.linking.model.Device;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zcf.common.json.Body;
import com.zcf.pojo.User;
import com.zcf.service.UserServiceImpl;
import com.zcf.vo.out.LayuiJson;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhaoQi
 * @since 2019-03-18
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserServiceImpl UserServiceImpl;
	/**
	 * 微信登录
	 * @param user
	 * @return
	 */
	@PostMapping("wxlogin")
	@ResponseBody
	public Body wxLogin(User user, HttpServletRequest request, HttpSession session, Device device){
		return UserServiceImpl.wxLogin(user,request,session);
	}

	/**
	 * 手机登录
	 * @param user
	 * @return
	 */

	@PostMapping("phonelogin")
	@ResponseBody
	public Body phoneLogin(User user,HttpServletRequest request,HttpSession session){
		return UserServiceImpl.phoneLogin(user,request,session);
	}

	/**
	 * 发送短信验证码
	 */
	@PostMapping("/sendSms")
	@ResponseBody
	public Body sendSms(HttpServletRequest request, String phone, HttpServletResponse response) {
        /* 允许跨域的请求头 */
        return  UserServiceImpl.SendContent(phone);
	}
	/**
	 * 用户注册
	 * @param user
	 * @return
	 */
	@PostMapping("register")
	@ResponseBody
	public Body register(User user,HttpServletRequest request,String code,String sid) {
		return UserServiceImpl.register(user, code,request);
	}
	/**
	 * 头像、昵称编辑
	 * @param user
	 * @return
	 */
	@PostMapping("update")
	@ResponseBody
	public Body update(User user){
		return UserServiceImpl.update(user);
	}
	/**
	 * 昵称编辑
	 * @param user
	 * @return
	 */
	@PostMapping("updateName")
	@ResponseBody
	public Body updateName(User user){
		return UserServiceImpl.updateName(user);
	}

	/**
	 * 头像编辑
	 * @param user
	 * @return
	 */
	@PostMapping("updatePhoto")
	@ResponseBody
	public Body updatePhoto(User user){
		return UserServiceImpl.updatePhoto(user);
	}
	
	/**
	 * 切换用户、退出
	 * @param user
	 * @return
	 */
	@PostMapping("exit")
	@ResponseBody
	public Body exit(User user){
		return UserServiceImpl.exit(user);
	}
	
	/**
	 * 用户列表
	 * @param user
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	
	@GetMapping("getUsers")
    @ResponseBody
    public LayuiJson getUsers(User user,@RequestParam(value = "pageNum") int pageNum,
                              @RequestParam(value = "pageSize") int pageSize){
        return UserServiceImpl.getUsers(user,pageNum,pageSize);
    }
	/**
	 * 删除某个用户
	 * @param user
	 * @return
	 */
	@PostMapping("delete")
    @ResponseBody
    public Body delete(User user ){
		return UserServiceImpl.delete(user);
	}
	
	/**
	 * 获取某个用户
	 * @param userid
	 * @return
	 */
	@PostMapping("getuser")
	@ResponseBody
	public Body getUser(Long userid ){
		return UserServiceImpl.getUser(userid);
	}

	/**
	 * 游戏统计
	 * @return
	 */
	@PostMapping("getusernum")
	@ResponseBody
	public LayuiJson getusernum(@RequestParam(value = "pageNum") int pageNum,
            @RequestParam(value = "pageSize") int pageSize){
		return UserServiceImpl.getusernum(pageNum,pageSize);
	}
	/**
	 * 找回密码
	 * @param user
	 * @return
	 */
	@PostMapping("restpassword")
    @ResponseBody
	public Body restpassword(User user, String code,HttpServletRequest request){
		return UserServiceImpl.restpassword(user,code,request);
	}
	/**
	 * 代理编辑
	 * @param user
	 * @return
	 */
	@PostMapping("editagent")
	@ResponseBody
	public Body editagent(User user){
		return UserServiceImpl.editagent(user);
	}
	
	
}

